package com.yunyao.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunyao.common.constant.Constants;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.common.dto.DeptTreeDto;
import com.yunyao.common.dto.base.BaseAreaDto;
import com.yunyao.dao.model.MacroBaseArea;
import com.yunyao.dao.service.system.IMacroBaseAreaService;
import com.yunyao.framework.service.base.BaseAreaService;
import com.yunyao.framework.vo.base.BaseAreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chenyejian
 * @Date 2024/9/3 23:52
 */
@Slf4j
@Service
public class BaseAreaServiceImpl implements BaseAreaService {
    @Autowired
    private IMacroBaseAreaService iMacroBaseAreaService;

    @Override
    public List<BaseAreaVO> getList(BaseAreaDto baseAreaDto) {
        LambdaQueryWrapper<MacroBaseArea> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MacroBaseArea::getFDeletemark, DataDeletedStatus.NO.getType())
                .eq(MacroBaseArea::getFEnabledmark, Constants.STRING_ONE)
                .eq(MacroBaseArea::getFParentid, baseAreaDto.getParentId()).orderByAsc(MacroBaseArea::getFSortcode);
        return iMacroBaseAreaService.list(queryWrapper).stream().map(this::convertDao2Vo).toList();
    }

    private BaseAreaVO convertDao2Vo(MacroBaseArea macroBaseArea) {
        BaseAreaVO baseAreaVO = new BaseAreaVO();
        BeanUtils.copyProperties(macroBaseArea, baseAreaVO);
        return baseAreaVO;
    }

}
